package jpsearchcore;

import java.util.List;

import jpsearchcore.ContentDesciption.CDOrganizationType;

public class Publisher {
	private Person PersonName = null;
	private CDOrganizationType OrganizationInformation = null;

	public Publisher(){}

	public Publisher(Person p, CDOrganizationType ot){
		PersonName = p;
		OrganizationInformation = ot;
	}

	public Publisher(Publisher p){
		PersonName = p.getPersonName();
		OrganizationInformation = p.getOrgInfo();
	}

	public Publisher(String GName, String FName, List<String> OrgInfoName, List<String> OrgInfoAddName, List<String> OrgInfoAddDesc){
		PersonName = new Person(GName, FName);
		OrganizationInformation = new CDOrganizationType(OrgInfoName, new Place("", OrgInfoAddName, OrgInfoAddDesc));
	}

	public Publisher(PublisherType pT){
		List<Object> data = pT.getPersonNameOrOrganizationInformation();
		for(Object o : data){
			if(o instanceof PersonNameType){
				//Publishers Names				
				PersonName = new Person((PersonNameType)o);
			}
			else if(o instanceof OrganizationType){
				//Publishers Organization Information
				OrganizationType ot = (OrganizationType)o;
				OrganizationInformation = new CDOrganizationType(ot);
			}
		}
	}

	public Person getPersonName(){
		return PersonName;
	}

	public String getPersonGivenName(){
		if(PersonName != null)
			return PersonName.getGivenName();
		return null;
	}

	public String getPersonFamilyName(){
		if(PersonName != null)
			return PersonName.getFamilyName();
		return null;
	}

	public CDOrganizationType getOrgInfo(){
			return OrganizationInformation;
	}

	public String getOrgInfoName(){
		if(OrganizationInformation != null)
			return OrganizationInformation.getName();
		return null;
	}

	public String getOrgInfoAddressName(){
		if(OrganizationInformation != null)
			return OrganizationInformation.getAddressName();
		return null;
	}

	public String getOrgInfoAddressDescr(){
		if(OrganizationInformation != null)
			return OrganizationInformation.getAddressDescription();
		return null;
	}

	public void setPersonName(Person personName) {
		PersonName = personName;
	}

	public void setPersonGivenName(String givenName){
		PersonName.setGivenName(givenName);
	}
	public void setPersonFamilyName(String familyName){
		PersonName.setFamilyName(familyName);
	}

	public void setOrgInfoName(String name){
		OrganizationInformation.getNames().clear();
		OrganizationInformation.getNames().add(name);
	}

	public void setOrgInfoAddressName(String name){
		OrganizationInformation.getAddress().getName().clear();
		OrganizationInformation.getAddress().getName().add(name);
	}

	public void setOrgInfoAddressDescription(String name){
		OrganizationInformation.getAddress().getDescription().clear();
		OrganizationInformation.getAddress().getDescription().add(name);
	}

	public void setOrgInfo(CDOrganizationType cdo) {
		OrganizationInformation = cdo;
	}

}
